#ifndef __HU6280_H__
#define __HU6280_H__

#define BAD_OPCODE		0x80000000
#define CPU_RESET		0x01
#define CPU_NMI			0x02
#define CPU_TIMER		0x04
#define CPU_IRQ1		0x08
#define CPU_IRQ2		0x10

typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
typedef signed long long int s64;

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long int u64;

typedef u8 (*readfunc_t)(u32);
typedef void (*writefunc_t)(u32,u8);

typedef struct	hu6280_s {
	u8 a,x,y,s,f;	// accumulator, x, y, stack pointer and flags
	u16 pc;			// program counter
	u64 cycles;		// cycle counter
	u8 needirq;		// if we need nmi, irq, etc
	
	//logical pages, 8 8kb pages (will always point to one of our physical pages)
	u8 memorymap[8];

	//physical pages, 256 8kb pages
	readfunc_t phys_op_func[256];
	readfunc_t phys_read_func[256];
	writefunc_t phys_write_func[256];
	u8 *phys_op_page[256];
	u8 *phys_read_page[256];
	u8 *phys_write_page[256];
} hu6280_t;

#ifdef __cplusplus
extern "C" {
#endif

u8 hu6280_op(u32 addr);
u8 hu6280_read(u32 addr);
void hu6280_write(u32 addr,u8 data);
u16 hu6280_disassembleopcode(char *buffer,u16 opcodepos);
u8 hu6280_getlastopcode();
u16 hu6280_getlastopcodepc();
u8 hu6280_getcurrentopcode();
u16 hu6280_getcurrentopcodepc();
u8 hu6280_getnextopcode();
u16 hu6280_getnextopcodepc();
u16 hu6280_getvector(u8 v);
u32 hu6280_getcycles();
void hu6280_addcycles(u32 numcycles);
void hu6280_setdata(hu6280_t *newdata);
void hu6280_getdata(hu6280_t **newdata);
void hu6280_push(u8 data);
u8 hu6280_pop();
void hu6280_init();

void hu6280_setirq(int mask);
void hu6280_clearirq(int keepmask);
void hu6280_reset();
u32 hu6280_step();

#ifdef __cplusplus
}
#endif

#endif
